<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var obj = {
      _myName: '星星',
      _age: 13,
      get myName() {
        console.log('获取myName');
        return this._myName
      },
      set myName(val) {
        console.log('给_myName赋值');
        this._myName = val
      }
    }
    Object.defineProperty(obj, '_myName', {
      configurable: true,
      enumerable: true,
      value: 'xiaohong',
      writable: true
    })
    console.log(obj);
    Object.defineProperty(obj, 'age', {
      configurable: true,
      enumerable: false,
      get: function () {
        console.log('进入age的get方法');
        return this._age
      },
      set: function (val) {
        console.log('进入age的set方法');
        this._age = val
      }
    })
    obj.age = '17'
    console.log(obj);
    console.log(Object.keys(obj));
    console.log(Object.getOwnPropertyNames(obj));

    
  </script>
</body>

</html>